package com.humi.partner.manager.web;

import com.humi.partner.manager.model.partnerType.PartnerTypeListQueryResponse;
import org.springframework.web.bind.annotation.RestController;
import	java.util.ArrayList;

import	java.net.Authenticator;
import	java.awt.PageAttributes.MediaType;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;

import com.humi.cloud.common.model.Result;

import com.humi.partner.common.entity.PartnerType;

import com.humi.partner.manager.model.partnerType.PartnerTypeAddQueryRequest;
import com.humi.partner.manager.model.partnerType.PartnerTypeAddQueryResponse;
import com.humi.partner.manager.model.partnerType.PartnerTypeListQueryRequest;
import com.humi.partner.manager.service.ManagerPartnerTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaTypeEditor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

/**
 * @Auther: lishijie
 * @Date: 2019/10/11 13:55
 * @Description:Codes are far away from bugs with the animal protecting
 */
@RestController
@RequestMapping(value = "/partner_type")
@Api(produces = APPLICATION_JSON_UTF8_VALUE, tags = "中台-伙伴类型基础数据")
public class ManagerPartnerTypeController {

    @Autowired
    ManagerPartnerTypeService managerPartnerTypeService;


    @PostMapping("/lib/page")
    @ApiOperation(value = "分页查询伙伴类型列表",notes ="伙伴类型",response = PartnerTypeListQueryRequest.class)
    public Callable<Result> getPartnerTypeLibPage(@Valid @ApiParam @RequestBody PartnerTypeListQueryRequest request, BindingResult error){
        return () -> error.hasErrors() ? Result.argumentFail(error.getFieldError().getDefaultMessage()) : this.managerPartnerTypeService.getPertnerType(request);
    }

    @GetMapping("/getuseFlag")
    @ApiOperation(value = "修改启用类型", notes = "有id时就进行修改启用类型",response = PartnerTypeListQueryRequest.class)
    public Callable<Result> getuseFlag(@Valid @ApiParam("是否启用：0停用；1启用") @RequestParam("id") String id,int flag) {
        return () ->  managerPartnerTypeService.getuseFlag(id, flag);
    }

    @PostMapping("/getPertnerTypeAdd")
    @ApiOperation(value = "添加或修改伙伴类型",notes ="有id就进行修改，判断没id就进行添加伙伴类型",response = PartnerTypeAddQueryRequest.class)
    public Callable<Result> getPertnerTypeAdd(@Valid @ApiParam @RequestBody PartnerTypeAddQueryRequest request, BindingResult error){
        return () -> error.hasErrors() ? Result.argumentFail(error.getFieldError().getDefaultMessage()) : this.managerPartnerTypeService.getPertnerTypeAdd(request);
    }
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "获取伙伴类型管理详情", response = PartnerTypeAddQueryResponse.class)
    public Callable<Result> getPartnerTypeOrderDetail(@PathVariable(name = "id",required =true) String id) {
        return () -> this.managerPartnerTypeService.getPartnerTypeOrderDetail(id);
    }


    @GetMapping("/lib/del")
    @ApiOperation(value = "通过id删除伙伴类型", notes = "成功则返回提示语，不成功则返回失败信息", response = PartnerTypeListQueryResponse.class)
    public Callable<Result> delPartnerTypeById(@Valid @ApiParam("伙伴类型ID") @RequestParam("id") String  id) {
        return () ->  managerPartnerTypeService.delPartnerTypeById(id);
    }

}
